#***********************************************************
#* Copyright (c) 2006, Zhimin Zhan.
#* Distributed open-source, see full license in MIT-LICENSE
#***********************************************************

module RWebUnit

# WebPage (children of AbstractWebPage) encapsulates a real web page.
# For example,
#  beginAt("/home")
#  @browser.clickLinkWithText("/login")
#  @browser.setFormElement("username", "sa")
# Can be rewritten to
#  beginAt("/home")
#  home_page = HomePage.new
#  login_page = home_page.clickLoginLink
#  login_page.enterUserName("sa")
#
# So you only need change in LoingPage class if UI changes, which happen quite often.
class AbstractWebPage

  # browser: passed to do assertion within the page
  # page_text: text used to identify the page, title will be the first candidate
  attr_accessor :browser, :page_text

  def initialize(ie, page_text=nil)
    @browser = ie
    @page_text = page_text
    assertOnPage
  end

  def assertTextPresent(text)
    @browser.assertTextPresent(text)
  end

  def assertTextInElement(elementID, text)
    @browser.assertTextInElement(elementID, text)
  end
  
  def assertOnPage()
    assertTextPresent(@page_text) if @page_text
  end

  def assertNotOnPage()
    assertTextNotPresent(@page_text) if @page_text
  end

  def submit
    @browser.submit
  end

  def getElementValue(elementId)
    @browser.getElemenValue(elementId)
  end

  def dumpResponse(stream = nil)
    @browser.dumpResponse(stream)
  end
  
end

end